package com.zisu.aradvertising.service.impl;

import com.zisu.aradvertising.pojo.*;
import com.zisu.aradvertising.pojo.business.Cooperation1;
import com.zisu.aradvertising.repository.*;
import com.zisu.aradvertising.service.Cooperation1Service;
import com.zisu.aradvertising.service.CooperationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class Cooperation1ServiceImpl implements Cooperation1Service {
    //实例化抽象类
    @Resource
    private DaoCreater daoCreater;
    @Resource
    private DaoCooperation1 daoCooperation1;
    @Resource
    private DaoAdvertiserSpace daoAdvertiserSpace;
    @Resource
    private DaoVideo daoVideo;
    @Resource
    private DaoAdvertiser daoAdvertiser;
    @Resource
    private DaoProduct daoProduct;
    @Resource
    private DaoSign daoSign;

    @Override
    public List<Cooperation1> findallbypidService(int pid){
        //将所有的合作信息提取出来
        List<Cooperation1> list1=daoCooperation1.findAllByPid(pid);
        List<Cooperation1> list2=new ArrayList<>();
        //对和合作信息进行过滤，找出所有待确认状态的合作信息
        for(Cooperation1 x:list1){
            if(x.getCostate().equals("待确认"))
                list2.add(x);
        }
        for (Cooperation1 x:list2){
            //将合作对应的广告位提取出来
            AdvertiserSpace advertiserSpace=daoAdvertiserSpace.findByApid(x.getApid());
            //将广告位对应的视频找出来
            Video video =daoVideo.findByVid(advertiserSpace.getVid());
            x.setVideo(video);
            //将视频对应的视频创作者找出来
            Creater creaetr=daoCreater.findByCid(video.getVid());
            x.setCreater(creaetr);
        }
        return list2;
    }
    //返回交易记录的所有合作信息
    public List<Cooperation1> findallbypidjiaoyijiluService(int pid){
        //将所有的合作信息提取出来
        List<Cooperation1> list1=daoCooperation1.findAllByPid(pid);
        List<Cooperation1> list2=new ArrayList<>();
        //对和合作信息进行过滤，找出所有待确认状态的合作信息
        for(Cooperation1 x:list1){
            if(x.getCostate().equals("待确认"))
            {System.out.println("可以的");}
             else{
                 System.out.println(x.toString());
                 list2.add(x);}
        }
        for (Cooperation1 x:list2){
            //将合作对应的广告位提取出来
            AdvertiserSpace advertiserSpace=daoAdvertiserSpace.findByApid(x.getApid());
            //将广告位对应的视频找出来
            Video video =daoVideo.findByVid(advertiserSpace.getVid());
            x.setVideo(video);
            //将视频对应的视频创作者找出来
            Creater creaetr=daoCreater.findByCid(video.getVid());
            x.setCreater(creaetr);
        }
        return list2;
    }

    //返回up主一个广告位下的待处理记录
    @Override
    public List<Cooperation1> findallbyapidgoingService(int apid){
        List<Cooperation1> cooperation1s=daoCooperation1.findAllByApid(apid);
        List<Cooperation1> list2=new ArrayList<>();
        //对和合作信息进行过滤，找出所有待确认状态的合作信息
        for(Cooperation1 x:cooperation1s){
            if(x.getCostate().equals("待确认")){
                list2.add(x);}
        }
        for (Cooperation1 x:list2){
            //将Sign信息提取出来
            Sign sign=daoSign.findByCoid(x.getCoid());
            //将合作对应的广告商提取出来
            Advertiser advertiser=daoAdvertiser.findByAid(sign.getAid());
            x.setAdvertiser(advertiser);
            //将合作对应的产品找出来
            Product product=daoProduct.findByPid(x.getPid());
            x.setProduct(product);
        }
        return list2;
    }


    //返回up主一个广告位下的已成交记录
    public List<Cooperation1> findallbyapidoverService(int apid){
        List<Cooperation1> cooperation1s=daoCooperation1.findAllByApid(apid);
        System.out.println(cooperation1s);

        List<Cooperation1> list2=new ArrayList<>();
        //对和合作信息进行过滤，找出所有待确认状态的合作信息
        for(Cooperation1 x:cooperation1s){
            if(x.getCostate().equals("待确认"))System.out.println("ok");
            else { list2.add(x);}
        }
        System.out.println(list2);
        for (Cooperation1 x:list2){
            //将Sign信息提取出来
            Sign sign=daoSign.findByCoid(x.getCoid());
            System.out.println(sign);
            //将合作对应的广告商提取出来
            Advertiser advertiser=daoAdvertiser.findByAid(sign.getAid());
            x.setAdvertiser(advertiser);
            System.out.println(advertiser);
            //将合作对应的产品找出来
            Product product=daoProduct.findByPid(x.getPid());
            x.setProduct(product);
            System.out.println(product);
            System.out.println("此时"+list2);
        }
        System.out.println(list2);
        if (list2.size()==0)
            return null;
        else
            return list2;
    }

}








